package com.example.smsreceiver;

import android.content.DialogInterface;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Toast;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

public class Main3Activity extends AppCompatActivity implements View.OnClickListener {
    EditText user;
    EditText pwd;
    CheckBox checkBox;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main3);
        Button btn = (Button) findViewById(R.id.btnlogin);
        user = (EditText) findViewById(R.id.user);
        pwd = (EditText) findViewById(R.id.pwd);
        checkBox = (CheckBox)findViewById(R.id.checkbox);

        btn.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.btnlogin:
                String name = user.getText().toString();
                String password = pwd.getText().toString();

                // 点击登陆 如果选择记住密码
                if (checkBox.isChecked()){
                    // 确定文件名和路径
                    File file = new File("data/data/com.example.smsreceiver/info.txt");
                    try {
                        FileOutputStream fos = new FileOutputStream(file);
                        fos.write((name + ":"+ password).getBytes());
                        fos.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }else{
                    Toast.makeText(Main3Activity.this,"",Toast.LENGTH_LONG);
                }
                break;
            default:
                break;
        }
    }
}
